package com.dmap.community.service.community.impl;

import com.dmap.community.dao.ReplyCommentPraiseMapper;
import com.dmap.community.dao.ReplyPraiseMapper;
import com.dmap.community.po.ReplyCommentPraise;
import com.dmap.community.po.ReplyCommentPraiseExample;
import com.dmap.community.po.ReplyPraise;
import com.dmap.community.po.ReplyPraiseExample;
import com.dmap.community.service.community.PraiseService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * \* User: silent
 * \* Date: 14/11/17 Time: 10:51
 * \* Description: 点赞服务模块
 * \
 */
@Service
public class PraiseServiceImpl implements PraiseService {

    @Resource
    private ReplyPraiseMapper replyPraiseMapper;

    @Resource
    private ReplyCommentPraiseMapper replyCommentPraiseMapper;

    @Override
    public int insertReplyPraise(long replyId, long userId) {
        ReplyPraise replyPraise = new ReplyPraise();
        replyPraise.setReplyId(replyId);
        replyPraise.setUserId(userId);
        return replyPraiseMapper.insertSelective(replyPraise);
    }

    @Override
    public int insertReplyCommentPraise(long commentId, long userId) {
        ReplyCommentPraise replyCommentPraise = new ReplyCommentPraise();
        replyCommentPraise.setCommentId(commentId);
        replyCommentPraise.setUserId(userId);
        return replyCommentPraiseMapper.insertSelective(replyCommentPraise);
    }

    @Override
    public int deleteReplyPraise(long replyId, long userId) {
        ReplyPraiseExample replyPraiseExample = new ReplyPraiseExample();
        replyPraiseExample.createCriteria().andReplyIdEqualTo(replyId).andUserIdEqualTo(userId);
        return replyPraiseMapper.deleteByExample(replyPraiseExample);
    }

    @Override
    public int deleteReplyCommentPraise(long commentId, long userId) {
        ReplyCommentPraiseExample replyCommentPraiseExample = new ReplyCommentPraiseExample();
        replyCommentPraiseExample.createCriteria().andCommentIdEqualTo(commentId).andUserIdEqualTo(userId);
        return replyCommentPraiseMapper.deleteByExample(replyCommentPraiseExample);
    }

    @Override
    public int countReplyPraise(long relyId) {
        ReplyPraiseExample replyPraiseExample = new ReplyPraiseExample();
        replyPraiseExample.createCriteria().andReplyIdEqualTo(relyId);
        return replyPraiseMapper.countByExample(replyPraiseExample);
    }

    @Override
    public int countReplyCommentPraise(long commentId) {
        ReplyCommentPraiseExample replyCommentPraiseExample = new ReplyCommentPraiseExample();
        replyCommentPraiseExample.createCriteria().andCommentIdEqualTo(commentId);
        return replyCommentPraiseMapper.countByExample(replyCommentPraiseExample);
    }


}
